import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-04-06
 * Time: 14:59
 */
public class PullConsumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.建立连接
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("1.95.194.117");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("wangkun");
        connectionFactory.setPassword("200411");
        connectionFactory.setVirtualHost("study");
        Connection connection = connectionFactory.newConnection();

        //2.通信
        Channel channel = connection.createChannel();

        //3.声明队列
        channel.queueDeclare("message.queue",true,false,false,null);

        //4.拉模式获取信息
        GetResponse getResponse = channel.basicGet("message.queue", true);
        System.out.println("拉模式获取消息: " + getResponse.toString());



        //5.资源关闭
        /*channel.close();
        connection.close();*/
    }
}
